package com.showcai.controller.index;

import com.showcai.controller.base.BaseController;
import com.showcai.module.AdminMenu;
import com.showcai.module.AdminUser;
import com.showcai.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.*;

/**
 * Created by Baggio on 2017/2/22.
 */
@RequestMapping("/index")
@Controller
public class AdminIndexContorller extends BaseController {
   @Autowired
   MenuService menuService;
    @RequestMapping(value = "/index")
    public ModelAndView index(HttpServletRequest request) {
        System.out.println("=============================index==============================================>>>>>>");
        ModelAndView mov = new ModelAndView();
        mov.setViewName("index");
       Map<String, String> map = new HashMap<>();
        AdminUser adminUser =super.getAdminUserBySession();
        if(adminUser!=null){
            map.put("roleId", String.valueOf(adminUser.getRoleId()));
            map.put("tid", String.valueOf(adminUser.getTid()));
        }
        List<AdminMenu> menuList = menuService.selectMenuListForRole(map);
        mov.addObject("menuList", menuList);
        return mov;

    }

    @RequestMapping(value = "/welcome")
    public ModelAndView welcome(HttpServletRequest request) {
        System.out.println("=============================index==============================================>>>>>>");
        ModelAndView mov = new ModelAndView();
        mov.setViewName("admin/welcome");
        return mov;

    }

}
